local function HasActiveTotem()
  local active = false
  for i = 1, 4 do
    active = active or GetTotemInfo(i)
  end
  return active
end


function Ankhy_Shaman_2()

local vTalent = {GetTalentInfo(16)}
local vGotUnleashedFury = false
if vTalent[6] == true then vGotUnleashedFury = true else vGotUnleashedFury = false end

		ccrCastBuffIfMissing("Lightning Shield")
		
		local v1, v2, v3, v4, v5, v6 = GetWeaponEnchantInfo()
		if v1 == nil then ccrCast("Windfury Weapon") end
		if v4 == nil then ccrCast("Flametongue Weapon") end
		if ccrPlayerIsInCombat() then	
			if SpellIsReady("Fire Elemental Totem") and ccrTargetIsBoss() and ccrTargetHasMyDebuff("Flame Shock")
				then
				ccrCast("Fire Elemental Totem")
				return
			end
			if SpellIsReady("Elemental Mastery") and ccrTargetIsBoss() and ccrTargetHasMyDebuff("Flame Shock")
				then
				ccrCast("Elemental Mastery")
				return
			end
			if SpellIsReady("Ascendance") and not ccrPlayerHasBuff("Ascendance") and ccrTargetIsBoss() and ccrTargetHasMyDebuff("Flame Shock")
				then
				ccrCast("Ascendance")
				return
			end
			
			if not HasActiveTotem()
				then
					ccrCastAttack("Searing Totem")
				return
			else
			if vGotUnleashedFury then
				if SpellIsReady("Unleash Elements")
					then
					ccrCastAttack("Unleash Elements")
					return 
				else
			end
					if ccrPlayerHasBuff("Maelstrom Weapon") and ccrUnitHasBuffStacks("player", "Maelstrom Weapon", 5)
						then
						ccrCastAttack("Lightning Bolt")
						return
					else
						if SpellIsReady("Stormblast")
							and ccrTargetIsWithinMeleeRange()
							then
							ccrCastAttack("Stormblast")
							return
						else	
							if SpellIsReady("Stormstrike")
								and ccrTargetIsWithinMeleeRange()
								then
								ccrCastAttack("Stormstrike")
								return
							else
								if not ccrTargetHasMyDebuff("Flame Shock") and ccrPlayerHasBuff("Unleash Flame")
									then
									ccrCastAttack("Flame Shock")
									return
								else
								if not ccrTargetHasMyDebuff("Flame Shock") and not ccrPlayerHasBuff("Unleash Flame") and onCD("Unleashed Elements") and SpellCDDuration("Unleashed Elements", 5)
									then
									ccrCastAttack("Flame Shock")
									return
								else
									if SpellIsReady("Lava Lash")
										and ccrTargetIsWithinMeleeRange()
										then
										ccrCastAttack("Lava Lash")
										return
									else
										if SpellIsReady("Unleash Elements")
											then
											ccrCastAttack("Unleash Elements")
											return
										else
											if ccrPlayerHasBuff("Ascendance") and  ccrPlayerHasBuff("Maelstrom Weapon") and ccrPlayerHasBuffStacks("Maelstrom Weapon", 3)
												and SpellCanAttack("Lightning Bolt")
												then
												ccrCastAttack("Lightning Bolt")
												return
											else	
												if SpellIsReady("Earth Shock")
													then
													ccrCastAttack("Earth Shock")
													return
												else
													if SpellIsReady("Feral Spirit")
														then
														ccrCast("Feral Spirit")
														return
													else
														if ccrPlayerHasBuff("Maelstrom Weapon") and ccrPlayerHasBuffStacks("Maelstrom Weapon", 1)
															and SpellCanAttack("Lightning Bolt") or not ccrTargetIsWithinMeleeRange()
															then
															ccrCastAttack("Lightning Bolt")
															return
														end	
													end
												end
											end
										end	
									end
								end
							end
						end
					end
				end
			end
		end
	end	
								
end